<template>
  <div class="yx-input">
    <input
      @input="inpChange"
      :placeholder="placeholder"
      @blur="inpBlur"
      :type="type"
      :value="modelValue"
    />
    <slot name="text"> </slot>
    <slot name="icon"></slot>
    <slot name="button"></slot>
    <slot name="img"></slot>
    <!-- <div class="button"><slot name="button"></slot></div> -->
  </div>
</template>
<script>
export default {
  props: {
    modelValue: String,
    placeholder: String,
    type: String,
  },
  setup(props, ctx) {
    const inpChange = (e) => {
      ctx.emit("update:modelValue", e.target.value);
      //调用父组件传来的update事件 更新modelValue  更新为 当前input 输入的内容
    };

    const inpBlur = () => {
      ctx.emit("blur");
    };
    return {
      inpChange,
      inpBlur,
    };
  },
};
</script>
<style lang="scss" scoped>
.yx-input {
  width: 270px;
  height: 50px;
  background: #f5f5f5;
  font-size: 12px;
  color: #333;
  border-radius: 5px;
  display: flex;
  padding: 0 20px;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  margin-top: 15px;

  input {
    min-width: 50px;

    // width: 170px;
    flex: 1;
    height: 30px;
    border: none;
    background-color: rgba(0, 0, 0, 0) !important;
  }
  ::v-deep .text {
    color: #e12c1e;

    width: 35px;
    text-align: center;
  }
  //样式穿透针对于 加了scoped之后 不在一个页面的样式就不起作用了 可以加上：：v-deep样式穿透就能起作用了
  ::v-deep .icon {
    width: 30px;
    text-align: center;
    color: #d1cfce;
  }
  ::v-deep .img {
    width: 50%;
    height: 100%;
  }
  ::v-deep .button {
    width: 50%;
    height: 100%;
    border-left: 1px solid #ccc;
  }
}

.success {
  border: 1px solid rgb(56, 219, 36);
  background: rgb(225, 255, 223);
}
.error {
  border: 1px solid rgb(225, 44, 30);
  background: rgb(255, 233, 228);
}
</style>
